package bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Bean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String name;

    public String getName() {
        System.out.println("get方法");
        return name;
    }

    public Bean() {
        System.out.println("构造方法");
    }

    public void setName(String name) {
        System.out.println("set方法");
        this.name = name;
    }

    public Bean(String name) {
        this.name = name;
        System.out.println("有参构造方法");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("setBeanName方法");
        System.out.println(s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory方法");
        System.out.println(beanFactory.toString());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext方法");
        System.out.println(applicationContext.toString());
        String applicationName = applicationContext.getApplicationName();
        System.out.println(applicationName);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.setName("fbli");
        System.out.println("afterPropertiesSet方法");
    }

    private void init() {
        System.out.println("自定义init方法");
        System.out.println(this.getName());
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("destroy方法");
    }

    private void des() {
        System.out.println("自定义destroy");
    }
}
